OPC Studio User's Guide and Reference
Create<TValue>(String,String,String,Int32) Method
Example 



OpcLabs.EasyOpcClassic Assembly > OpcLabs.EasyOpc.DataAccess.Reactive Namespace > DAItemChangedObservable Class > Create Method : Create<TValue>(String,String,String,Int32) Method
Name of the machine (empty string for local computer).

The value represents a UNC or DNS computer name. Any string can be passed to this parameter (i.e. will not cause System.ArgumentException), but not all values make sense and will work when an operation using them is attempted. IPv6 addresses are normally enclosed between '[' and ']'.

The value of this parameter cannot be null (Nothing in Visual Basic).

Contains ProgID of the OPC server.

The value of this parameter cannot be null (Nothing in Visual Basic).

ID of the item that will be subscribed to.

The value of this parameter cannot be null (Nothing in Visual Basic).

How often should the updates be received (number of milliseconds)

Valid values of this parameter are in the range from -1 to 2147483647 (Int32.MaxValue).

Creates a new item change observable for OPC item, specifying machine name, server class, item ID, requested update rate, and percent deadband.
Syntax
'Declaration
 
<NotNullAttribute()>
Public Overloads Shared Function Create(Of TValue)( _
   ByVal machineName As String, _
   ByVal serverClass As String, _
   ByVal itemId As String, _
   ByVal requestedUpdateRate As Integer _
) As DAItemChangedObservable(Of TValue)
'Usage
 
Dim machineName As String
Dim serverClass As String
Dim itemId As String
Dim requestedUpdateRate As Integer
Dim value As DAItemChangedObservable(Of TValue)
 
value = DAItemChangedObservable.Create(Of TValue)(machineName, serverClass, itemId, requestedUpdateRate)

Parameters

machineName
Name of the machine (empty string for local computer).

The value represents a UNC or DNS computer name. Any string can be passed to this parameter (i.e. will not cause System.ArgumentException), but not all values make sense and will work when an operation using them is attempted. IPv6 addresses are normally enclosed between '[' and ']'.

The value of this parameter cannot be null (Nothing in Visual Basic).

serverClass
Contains ProgID of the OPC server.

The value of this parameter cannot be null (Nothing in Visual Basic).

itemId
ID of the item that will be subscribed to.

The value of this parameter cannot be null (Nothing in Visual Basic).

requestedUpdateRate
How often should the updates be received (number of milliseconds)

Valid values of this parameter are in the range from -1 to 2147483647 (Int32.MaxValue).

Type Parameters

TValue

Return Value

Returns an observable for changes in the given OPC item.

This method never returns null (Nothing in Visual Basic).

Remarks
The DAReactive.DefaultClientSelector selector will be used for OPC Data Access operations.
Example
// Shows how to create an observable for OPC-DA item changes, and subscribe to it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using System.Threading;
using OpcLabs.EasyOpc.DataAccess.Reactive;

namespace ReactiveDocExamples
{
    namespace _DAItemChangedObservable
    {
        partial class Subscribe
        {
            public static void Main1()
            {
                Console.WriteLine("Creating observable...");
                DAItemChangedObservable<double> ramp = 
                    DAItemChangedObservable.Create<double>("", "OPCLabs.KitServer.2", "Demo.Ramp", 1000);

                Console.WriteLine("Subscribing...");
                using (ramp.Subscribe(e => Console.WriteLine(
                    (e.Exception is null) ? e.Vtq.ToString() : e.Exception.GetBaseException().ToString())))
                {
                    Console.WriteLine("Waiting for 10 seconds...");
                    Thread.Sleep(10*1000);

                    Console.WriteLine("Unsubscribing...");
                }

                Console.WriteLine("Waiting for 2 seconds...");
                Thread.Sleep(2 * 1000);
            }
        }
    }
}
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also